<template>
  <zm-dialog
    :title="title"
    :visible.sync="value"
    append-to-body
    center
    top="30vh"
    size="mini"
    :before-close="dialogClose"
    :close-on-click-modal="false"
  >
    <el-form label-width="80px" :model="form" :rules="formRule" ref="form">
      <el-form-item prop="email" label="邮箱:" v-if="releaseStatus===5">
        <el-input v-model="form.email" class="w320" placeholder="请输入" />
      </el-form-item>
      <el-form-item prop="phone" label="电话:" v-else>
        <el-input
          v-model="form.phone"
          placeholder="请输入"
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="tr">
      <el-button type="default" @click="dialogClose">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </div>
  </zm-dialog>
</template>
<script>
import dialogMixin from '@/mixins/dialogMixin'
import {
  updateDyUserinfo,
} from "@/api/system/dyUserinfo";
import { operateBtn } from "../const"
export default {
  name: "Release",
  mixins: [dialogMixin],
  props:{
    releaseStatus:{
      type:Number,
      default:1,
    },
  },
  data() {
    return {
      form: {
       email:'',
       phone:'',
      },
      formRule: {
        email: [
          {
            required: true,
            message: '请输入!'
          }
        ],
        phone: [
          {
            required: true,
            message: '请输入!'
          }
        ]
      },
    }
  },
  mounted() {
    if (this.obj.id) this.form = { ...this.obj }
  },
  computed: {
    title() {
      const item = operateBtn.find(item => item.status === this.releaseStatus)
      return (item&&item.name)||'放行'
    }
},
  methods: {
    async submit() {
      let _valid = false
      this.$refs.form.validate((valid) => {
        _valid = valid
      })
      if (!_valid) {
        return
      }
      const params = {}
      if(this.releaseStatus===5){
        params.email = this.form.email
        params.phone = null
      }else{
        params.phone = this.form.phone
        params.email = null
      }
      // if(this.releaseStatus===3){
      //   params.phone = this.form.phone
      // }
      const res = await updateDyUserinfo(
        Object.assign({}, {...params},{id:this.obj.id,status:this.releaseStatus})
      )
      this.$emit('after-save')
      this.$message.success('放行成功!')
      this.dialogClose()
    }
  }
}
</script>
